<link rel="stylesheet" href="<?=PATH_URL.'static/css/admin/xekhach.css'?>" type="text/css">
<script type="text/javascript">
function searchContent(start, per_page) {}

function allowDrop(ev){console.log('allowDrop');
	ev.preventDefault();
}

function drag(ev){
	console.log(ev.target.id);
	ev.dataTransfer.setData("book_id",ev.target.id);
}

function drop(ev){console.log('drop');
	ev.preventDefault();
	var book_id=ev.dataTransfer.getData("book_id");console.log(book_id);
	var book_ele = document.getElementById(book_id);
	if(book_ele){
		ev.target.appendChild(book_ele);
	}
}

function ajax_book_list(){
	var url = '<?=PATH_URL.'process/ajax_book_list'?>';
	var selected_date = $('#booked_date').val();
	var schedule_id = $('.schedule_section .time_section a.time_item_active').find('span').text();
	$.post(url,{'selected_date':selected_date,'schedule_id':schedule_id},function(data){
		$('.book_list_section').html(data);
	});
}
function ajax_seat_list(){
	var url = '<?=PATH_URL.'process/ajax_seat_list'?>';
	var vehicle_id = $('#vehicle_id').val();
	vehicle_id = parseInt(vehicle_id);
	if(vehicle_id > 0){
		$.post(url,{'vehicle_id':vehicle_id},function(data){
			$('.seat_list_section').html(data);
		});
	}
}

$(document).ready(function(){
	// Schedule section filter
	$('.schedule_section .time_section a.time_item').click(function(){
		$('.schedule_section .time_section a.time_item').removeClass('time_item_active');
		$(this).addClass('time_item_active');
		ajax_book_list();
		return false;
	});
	$('.schedule_section .date_section select.booked_date').change(function(){
		ajax_book_list();
		return false;
	});
	
	// Driver-vehicle section filter
	$('.xeplich_content_section .vehicle_list select.vehicle_id').change(function(){
		ajax_seat_list();
		return false;
	});
	ajax_seat_list();
});
</script>
<div class="head_table_1">
	<div class="head_title_table">Xếp lịch</div>
</div>
<div id="indexView" class="table-1 process_view_content_container">
	<table>
		<td width="50%" valign="top">
			<div class="schedule_section">
				<div class="date_section">
					<div class="date_section_label">
						Ngày khởi hành
					</div>
					<div class="date_section_content">
						<select id="booked_date" class="booked_date">
						<?php
						$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("Y"));
						$date = 0;
						for($i=-2;$i<=2;$i++){
							$date = mktime(0, 0, 0, date("m"), date("d")+$i, date("Y"));
							$selected = $date == $tomorrow ? 'selected="selected"' : '';
						?>
							<option value="<?=$date?>" <?=$selected?> ><?=date(DATETIME_FORMAT_VN_DATE,$date)?></option>
						<?php
						}
						?>
						</select>
					</div>
					<div class="clearAll"></div>
				</div>
				<div class="time_section">
					<div class="time_section_label">
						Giờ khởi hành
					</div>
					<div class="time_section_content">
						<?php
						$i = 0;
						foreach($schedule_list as $schedule){
							$start_time = strtotime($schedule['start_time']);
							$start_time = date(DATETIME_FORMAT_HOUR,$start_time);
							$style = $i == 0 ? 'style="margin-left:0;"' : '';
						?>
							<a class="time_item" <?=$style?>>
								<?=$start_time?>
								<span style='display:none;'><?=$schedule['id']?></span>
							</a>
						<?php
							$i++;
						}
						?>
					</div>
					<div class="clearAll"></div>
				</div>
			</div>
			<div class="book_list_section">
			</div>
		</td>
		<td valign="top">
			<div class="xeplich_content_section">
				<div class="driver_list">
					<div class="driver_list_label">
						Tài xế
					</div>
					<div class="driver_list_content">
						<select id="driver_id" class="driver_id">
							<?php
							$i = 0;
							foreach($driver_list as $driver){
								$driver_id = $driver['id'];
								$selected = '';
							?>
								<option value="<?=$driver_id?>" <?=$selected?> ><?=$driver['name']?></option>
							<?php
								$i++;
							}
							?>
						</select>
					</div>
				</div>

				<div class="vehicle_list">
					<div class="vehicle_list_label">
						Xe
					</div>
					<div class="vehicle_list_content">
						<select id="vehicle_id" class="vehicle_id">
							<?php
							$i = 0;
							foreach($vehicle_list as $vehicle){
								$vehicle_id = $vehicle['id'];
								$selected = '';
							?>
								<option value="<?=$vehicle_id?>" <?=$selected?> ><?=$vehicle['number_plate']?></option>
							<?php
								$i++;
							}
							?>
						</select>
					</div>
				</div>
			</div>
			<div class="seat_list_section">
			</div>
		</td>
	</table>
</div>